home *** CD-ROM | disk | FTP | other *** search
- Path: news2.noc.netcom.net!news
- Newsgroups: comp.lang.c
- Subject: Re: goto
- Message-ID: <314E0BDE.7933@willows.com>
- From: Tarang Deshpande <tarang@willows.com>
- Date: Mon, 18 Mar 1996 17:20:30 -0800
- References: <Pine.OSF.3.91.960313102715.10701D-100000@io.UWinnipeg.ca>
- Organization: NETCOM Network Operations
- NNTP-Posting-Host: daffy.willows.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
-
- Bill Simpson wrote:
- >
- > There was a goto thread lately, and my problem is to state this algorithm
- > cleanly without gotos (which I think is easy, but my attempts have been
- > failures).
- >
- > 0. x=0;
- > 1. x+=erand(maxmean);
- > 2. if (urand2()>rate(x)/maxrate)
- > goto step 1
- > 3. if (x<=XMAX)
- > {
- > setdot(x,y,z);
- > goto step 1
- > }
- > explanation:
- > erand(mean) returns exponential double random number with given mean
- > urand2() returns uniform double random number between 0 & 1
- > rate(). well the rate of the Poisson process varies with x
-
-
- x = 0;
- do
- {
- double uRand;
- double rateCalc;
-
- x += erand ( maxmean );
- uRand = urand2 ();
- rateCalc = rate ( x ) / maxrate;
- if ( urand <= rateCalc )
- if ( x <= XMAX )
- setdot ( x, y, z );
- } while ( ( x > XMAX ) || ( uRand > rateCalc ) );
-
-